/**
 * @author huangxunhui
 * Date: Created in 18/10/17 下午10:09
 * Utils: Intellij Idea
 * Description: 翻转整数
 */
public class Reverse_07 {

    public static int reverse(int x) {
        int rev = 0;
        while (x != 0){
            int pop = x % 10 ;
            x /= 10;
            if (rev > Integer.MAX_VALUE/10 || (rev == Integer.MAX_VALUE / 10 && pop > 7)) return 0;
            if (rev < Integer.MIN_VALUE/10 || (rev == Integer.MIN_VALUE / 10 && pop < -8)) return 0;
            rev = rev * 10 + pop;
        }
        return rev;
    }

    public static void main(String[] args) {
        System.out.println("result "+ reverse(123));
    }
}
